<?php
namespace app\admin\logic;

class IntegralLogic extends BaseLogic {

    /**
     * 获取积分明细查询条件
     * @param $department
     * @param $username
     * @param $integral_type
     * @param $start_time
     * @param $end_time
     * @return array
     */
    public function get_search_integral_maps($department,$username,$integral_type,$start_time,$end_time){
        $maps = [];

        if($department != '全部'){
            $u_maps = [];
            $u_maps[] = ['department','=',$department];
            $openids = model('user')->get_column($u_maps,'openid');
            $maps[] = ['openid','in',$openids];
        }

        if(!empty($username)){
            $u_maps = [];
            $u_maps[] = ['username','like','%' . $username . '%'];
            $openids = model('user')->get_column($u_maps,'openid');
            $maps[] = ['openid','in',$openids];
        }

        if($department != -1){
            if($integral_type == 0){
                $maps[] = ['integral','>=',0];
            }
            if($integral_type == 1){
                $maps[] = ['integral','<',0];
            }
        }

        if(!empty($start_time) && !empty($end_time)){
            $maps[] = ['c_time','between',[$start_time,$end_time]];
        }
        return $maps;
    }
}